'use strict'
const http = require('http')
const EventEmitter = require('events')
class RoomHttp extends EventEmitter {
  constructor () {
    super()
  }
  get (url) {
    var self = this
    http.get(url, function (res) {
      var buf = new Buffer(0)
      res.on('data', function (data) {
        buf = Buffer.concat([buf, data], data.length + buf.length)
      })
      res.on('end', () => {
        try {
          self.emit('info', JSON.parse(buf))
        } catch (e) {
          self.emit('info', null)
        } finally {

        }
      })
    }).on('error', (e) => {
      self.emit('info', null)
    })
  }
}
module.exports = RoomHttp
